<?php

if(count($this->orfaos)) {
    echo "<select id='id_ciclo' style='width:600px;' multiple name='evento_id[ ]' size='20' style='padding:5px;'>";
    $ult_cat="";
    foreach($this->orfaos as $result) {
        if($result->categoria<>$ult_cat){
            if($ult_cat!=""){echo "</optgroup>";}
            echo "<optgroup label='".$result->categoria."'>";
            $ult_cat = $result->categoria;
        }
    echo "<option value=".$result->id.">".$result->fullname."</option>";
    }
    echo "</optgroup></select>";
} else {
           echo 'ERROR: There was a problem with the query.';
}
?>